@extends('layouts.art')

@section('content')
<meta name="csrf-token" content="{{ csrf_token() }}" />

<a class="btn btn-primary" href="/art/create">添加文章</a>


@foreach( $arts as $art)
<div class="panel panel-default">
    <div class="panel-body">
        {{$art->title}}
        <a href="/art/{{$art->id}}" class="btn btn-info">阅读</a>
        <a href="/art/{{$art->id}}/edit" class="btn btn-info">修改</a>

        <form action="/art/{{$art->id}}" method="" style="display: inline-block;">
            {{csrf_field()}}
            <!-- {{ method_field('DELETE') }} -->

            <!-- <button type="submit" class="btn btn-danger">删除</button> -->
        </form>
            {{csrf_field()}}
            <button class="btn btn-danger" value="{{ $art->id }}" onclick="member_del(this,{{$art->id}})" >删除</button>
            <!-- <button class="btn btn-danger" value="{{ $art->id }}">删除</button> -->
    </div>
</div>
@endforeach

{!!$arts->render() !!}
<!-- {!! $arts->links() !!} -->

<script src="{{ URL::asset('/plugins/jQuery/jquery-1.8.2.min.js')}}"></script>
<script>
    $(function(){   
    var winH = $(window).height(); //页面可视区域高度 
    // alert(winH);  
    var i = 2; //设置当前页数   
    $(window).scroll(function () {   
        var pageH = $(document.body).height();   
        var scrollT = $(window).scrollTop(); //滚动条top   
        var aa = (pageH-winH-scrollT)/winH;   
        if(aa<0.02){   
            $.getJSON("/art/dis",{page:i},function(json){   
                if(json.data){   
                    // alert(1);
                    var str = "";   
                    $.each(json,function(a,array){   
                        
                        // var str = "<div class=\"panel panel-default\">";
                        // var str += "<div class=\"panel-body\">"+1+"</div></div>";
              
                        str = json.data[a].title;
                        // alert(2);
                        // str = '1';
                        // var str = "<div class=\"single_item\"><div class=\"element_head\">";   
                        // var str += "<div class=\"date\">"+array['date']+"</div>";   
                        // var str += "<div class=\"author\">"+array['author']+"</div>";   
                        // var str += "</div><div class=\"content\">"+array['content']+"</div></div>";   
                        $("body").append(str);   
                    });   
                    i++;   
                }else{   
                    // $(".nodata").show().html("别滚动了，已经到底了。。。"); 
                    alert('别滚动了，已经到底了。。。');  
                    return false;   
                }   
            });   
        }   
    });   
});  

function member_del(obj,id){
                $.ajax({
                    type: 'GET',
                    url:'art/delete',
                    dataType: 'json',
                    data:{id:id},
                    success: function(data){
                        $(obj).parent().parent().remove();
                        // layer.msg('已删除!',{icon:1,time:1000});
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
        }

</script>

@endsection